package com.wugui.datax.job.mapper.base;

import com.wugui.datax.job.entity.JobDatasource;
import com.wugui.datax.job.service.JobDatasourceService;
import com.wugui.datax.job.tool.query.HiveTemplate;
import com.wugui.datax.job.tool.query.RdbmsTemplate;
import com.wugui.datax.job.util.JdbcConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.sql.SQLException;

/**
 * @author luofei
 * @date 2021/6/25 17:31
 */
@Component
public class RdbmsMapper {
    /**
     * 数据源查询服务
     */
    @Autowired
    private JobDatasourceService jobDatasourceService;

    public RdbmsTemplate rdbmsTemplate(String  datasourceId) {
        RdbmsTemplate rdbmsTemplate = null;
        if (rdbmsTemplate==null){
            JobDatasource jobDatasource = jobDatasourceService.getDatasource(datasourceId);
            try {
                rdbmsTemplate = new RdbmsTemplate(jobDatasource);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return rdbmsTemplate;
    }

}
